package J5_25;

import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

public class test {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.next();
        StringBuilder res = new StringBuilder();
        Set<Character> set = new HashSet<>();
        for (int i = str.length()-1; i >=0 ; i--) {
            if (set.contains(str.charAt(i))) {
                continue;
            }
            set.add(str.charAt(i));
            res.append(str.charAt(i));
        }
        System.out.println(res.toString());
    }

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        PriorityQueue<Long> queue = new PriorityQueue<>();
        while (n-- > 0) {
            queue.offer(in.nextLong());
        }
        long res = 0;
        while (queue.size() > 1) {
            long t1 = queue.poll();
            long t2 = queue.poll();
            res += t1 + t2;
            queue.offer(t1 + t2);
        }
        System.out.println(res);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String str = in.next();
        int[] f = new int[26];
        int[] g = new int[26];
        int res = 0;
        for (int i = 0; i < n; i++) {
            res += f[str.charAt(i) - 'a'];
            f[str.charAt(i) - 'a'] = f[str.charAt(i) - 'a'] + i - g[str.charAt(i) - 'a'];
            g[str.charAt(i) - 'a'] = g[str.charAt(i) - 'a'] + 1;
        }
        System.out.println(res);
    }
}
